home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / BT_FIRST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.6 KB  |  61 lines

  1. /*  bt_first.c - position at start/end of index */
  2. #include   "stdio.h"
  3. #include   "btree.h"
  4. #include   "bt_macro.h"
  5.  
  6. extern     IX_DESC    *pci ;    /* global variable for current pix  */
  7.  
  8. int  go_first(pix)        /* go to first entry in index */
  9.   IX_DESC  *pix ;        /* points to an index descriptor */
  10.   {
  11.      BLOCK b ;
  12.  
  13.      pci = pix ;
  14.                 /* start at root level and */
  15.      first_ix(pci->dx.nl-1,pci->dx.rb,&b) ; /* set at first entry */
  16.      return( IX_OK ) ;
  17.   }
  18.  
  19. int  first_ix(l,r,pb)        /* set curr. pos. to first entry */
  20.   int    l ;            /* at this and lower levels */
  21.   RECPOS   r ;            /* curr. block for level l */
  22.   BLOCK *pb ;
  23.   {
  24.      CB(l) = r ;        /* set current block */
  25.      CO(l) = 0 ;        /* and offset */
  26.      retrieve_block(l,CB(l),pb,CURR) ; /* get the block */
  27.  
  28.      if( l > 0 )        /* set lower levels too */
  29.     first_ix(l-1,ENT_ADR(pb,0)->rptr,pb) ;
  30.   }
  31.  
  32.  
  33. int  go_last(pix)        /* go to last index entry (dummy) */
  34.   IX_DESC *pix ;        /* points to an index descriptor */
  35.   {
  36.      BLOCK b ;
  37.  
  38.      pci = pix ;
  39.      final_ix(pci->dx.nl-1,pci->dx.rb,&b) ; /* start at root */
  40.                 /* position of last entry */
  41.      return( IX_OK ) ;        /* success return code */
  42.   }
  43.  
  44.  
  45. int  final_ix(l,r,pb)        /* set curr. pos. to first entry */
  46.   int    l ;            /* at this and lower levels */
  47.   RECPOS   r ;            /* curr. block for level l */
  48.   BLOCK *pb ;
  49.   {
  50.      int off ;
  51.  
  52.      CB(l) = r ;        /* set current block */
  53.      retrieve_block(l,r,pb,CURR) ; /* get the block */
  54.      off = last_entry(pb) ;    /* curr. offset = last entry */
  55.      CO(l) = off ;
  56.      if( l > 0 )        /* set lower level too */
  57.     final_ix(l-1,ENT_ADR(pb,off)->rptr,pb) ;
  58.   }
  59.  
  60.  
  61.